<template>
	<view class="content fafafa" v-if="pageShow">
		<view class="ffffff evalBox margin_bottom3 border_2" v-for="item in list.data" :key="item.id">
			<view class="flexbetween">
				<view class="flexleft">
					<view class="imgBox margin_right2">
						<image :src="item.avatar" mode="widthFix"></image>
					</view>
					<view class="text_d color_ling">{{item.nickname}}</view>
				</view>
				<view class="text_five color_six">{{item.createtime_text}}</view>
			</view>
			<view class="text_a color_six margin_top">{{item.content}}</view>
			<view class="margin_top flexleft" v-if="item.images_arr.length">
				<view class="flexcenter" style="width: 33.33%;" v-for="(ite,ind) in item.images_arr" :key="ind" @click="lbtpriview(ind,item.images_arr)">
					<view class="evalImage">
						<image :src="ite" mode="widthFix"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="flexcenter placeholderBoxTop" v-if="!list.data.length">
			<image class="placeholderBox" src="/static/placeholderimg.png" mode="widthFix"></image>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type:1,//1商品评价，2服务评价
				listid:"",
				page:1,
				list:{
					data:[]
				},
				pageShow:false,
			}
		},
		onLoad(options) {
			this.type = options.type
			this.listid = options.id
			this.init()
		},
		methods:{
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					goods_id: this.listid,
				}
				let url = "/api/goods/getcommentlist"
				if(this.type==2){
					data = {
						page: page || 1,
						service_id: this.listid,
					}
					url ="/api/service/getcommentlist"
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
							this.pageShow = true
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			lbtpriview(index,arr) {
				var i = arr; //获取当前页面的轮播图数据
				//uniapp预览轮播图
				uni.previewImage({
					current: index, //预览图片的下标
					urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 30rpx;
	}

	// 评价
	.evalBox {
		padding: 30rpx;

		.imgBox {
			width: 73rpx;
			height: 73rpx;
			border-radius: 50%;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.evalImage {
			width: 152rpx;
			height: 152rpx;
			// border-radius: 50%;
			// overflow: hidden;

			image {
				width: 100%;
				height: 100%;
				border-radius: 18rpx;
			}
		}
	}
</style>